package com.bw.house.controller;

import java.util.Arrays;
import java.util.Map;

import com.bw.house.config.OssUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bw.house.entity.HouseRentEntity;
import com.bw.house.service.HouseRentService;
import com.bw.common.utils.PageUtils;
import com.bw.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 
 *
 * @author jwcz
 * @email 2898807664@qq.com
 * @date 2022-03-24 15:57:09
 */
@RestController
@RequestMapping("house/houserent")
public class HouseRentController {
    @Autowired
    private HouseRentService houseRentService;

    @Autowired
    private OssUtils ossUtils;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = houseRentService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @RequestMapping("/slist")
    public R slist(@RequestParam Map<String, Object> params){
        PageUtils page = houseRentService.slist(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/upload")
    public R upload(MultipartFile file) {
        R r = ossUtils.uploadFile(file);
        return r;
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{houseId}")
    public R info(@PathVariable("houseId") Integer houseId){
		HouseRentEntity houseRent = houseRentService.getById(houseId);

        return R.ok().put("houseRent", houseRent);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HouseRentEntity houseRent){
		houseRentService.save(houseRent);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HouseRentEntity houseRent){
		houseRentService.updateById(houseRent);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] houseIds){
		houseRentService.removeByIds(Arrays.asList(houseIds));

        return R.ok();
    }

}
